package cn.edu.hziee;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class UserServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String userName = request.getParameter("userName");
        String pwd = request.getParameter("pwd");
        String re_pwd = request.getParameter("re_pwd");
        RequestDispatcher rd = null;
        if (pwd.equals(re_pwd)) {
            String[] beers = request.getParameterValues("beer");
            System.out.println("userName:" + userName);
            System.out.println("pwd：" + pwd);
            System.out.println("re_pwd:" + re_pwd);
            if (beers != null) {
                for (String beer : beers) {
                    System.out.println("beer:" + beer);
                }
            }
            rd = request.getRequestDispatcher("ok.jsp");
        } else {
            rd = request.getRequestDispatcher("fail.jsp");
        }
        rd.forward(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        RequestDispatcher rd = request.getRequestDispatcher("index.jsp");
        rd.forward(request, response);
    }
}
